package com.xl.gradledemo;

import android.util.Log;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelStoreOwner;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ViewModleUtils {

    public static void process(Object clazz, ViewModelStoreOwner owner) {
        try {

            for (Field field : clazz.getClass().getFields()) {
                if (field.isAnnotationPresent(InjectViewModle.class)) {
                    ViewModel viewModel = ViewModleFactory.INSTANCE.createModle(owner, (Class<? extends ViewModel>) field.getDeclaringClass());
                    field.setAccessible(true);
                    field.set(clazz, viewModel);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("TAG", "process: " + e);
        }
    }

}
